/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package easyanimation.panel;

import easyanimation.frame.Constant;
import easyanimation.frame.MainWindow;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author tandn
 */
public class CStatusPanel extends JPanel
{
    private JTextField m_mouseViewLabel;
    //Zoom slider
    private JSlider m_zoomSlider;
    private JLabel m_zoomLabel;
    private JButton m_zoomNormalButton;

    public CStatusPanel(int iViewX, int iViewY)
    {
        setLayout(new FlowLayout(FlowLayout.RIGHT));
        setBorder(Constant.OBJ_BORDER_COMMON);
        //***********view position
        m_mouseViewLabel = new JTextField(Constant.STATUS_FIELD_WIDTH);
        m_mouseViewLabel.setFont(Constant.OBJ_FONT_PLAIN);
        m_mouseViewLabel.setPreferredSize(new Dimension(Constant.STATUS_FIELD_WIDTH * Constant.CHARACTOR_WIDTH, Constant.COMPONENT_SMALL_HEIGHT));
        m_mouseViewLabel.setEditable(false);
        m_mouseViewLabel.setHorizontalAlignment(JTextField.CENTER);
        m_mouseViewLabel.setText("(" + iViewX + "," + iViewY + ")");
        //************zoom
        m_zoomLabel = new JLabel(Constant.ZOOM_NORMAL + "%");
        m_zoomSlider = new JSlider(Constant.ZOOM_MIN, Constant.ZOOM_MAX, Constant.ZOOM_NORMAL);
        m_zoomSlider.setPreferredSize(new Dimension(200, Constant.COMPONENT_SMALL_HEIGHT + 7));
        m_zoomSlider.setPaintTicks(true);
        m_zoomSlider.setMajorTickSpacing(100);
        m_zoomSlider.setMinorTickSpacing(100);
        //m_zoomSlider.setPaintLabels(true);
        m_zoomSlider.setPaintTrack(true);
        m_zoomSlider.addChangeListener(new ChangeListener()
        {
            @Override
            public void stateChanged(ChangeEvent e)
            {
                m_zoomLabel.setText(m_zoomSlider.getValue() + "%");
                getCenterPanel().setZoomForCenter(m_zoomSlider.getValue());
            }
        });
        m_zoomNormalButton = new JButton(Constant.ZOOM_NORMAL + "%");
        m_zoomNormalButton.setPreferredSize(new Dimension((Constant.ZOOM_NORMAL + "%").length() * Constant.CHARACTOR_WIDTH, Constant.COMPONENT_SMALL_HEIGHT));
        m_zoomNormalButton.setMargin(Constant.OBJ_MARGIN);
        m_zoomNormalButton.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e)
            {
                m_zoomLabel.setText(Constant.ZOOM_NORMAL + "%");
                m_zoomSlider.setValue(Constant.ZOOM_NORMAL);                
                getCenterPanel().setZoomForCenter(Constant.ZOOM_NORMAL);
            }
        });
        add(m_zoomLabel);
        add(m_zoomSlider);
        add(m_zoomNormalButton);
        add(m_mouseViewLabel);
    }

    public void setMouseView(int x, int y)
    {
        m_mouseViewLabel.setText("(" + x + "," + y + ")");
    }

    public void setZoomForStatus(int zoom)
    {
        m_zoomLabel.setText(zoom + "%");
        m_zoomSlider.setValue(zoom);
    }
    
    public CCenterPanel getCenterPanel()
    {
        return MainWindow.getInstance().getCenterPanel();
    }
}

